package com.ftg.midamall.controller;

/**
 * @author 王子璇
 * @version 1.0
 * @date 2023/11/16 10:52
 */
import com.alibaba.fastjson2.JSONObject;
import com.ftg.midamall.comm.vo.RespMessUtil;
import com.ftg.midamall.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 上传功能
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/11/16 上午8:59
 */

@RestController
@RequestMapping("/upload")
@Api(tags = "上传功能")
public class UploadController {

    @Resource
    private UploadService uploadService;

    /**
     * 上传头像
     *
     * @param avatarFile 头像文件
     * @return 响应结果对象，包含上传结果信息
     */
    @PostMapping("/uploadAvatar")
    @ApiOperation(value = "上传图片")
    public RespMessUtil<JSONObject> uploadAvatar(
            @ApiParam("avatarFile") @RequestParam("avatarFile") MultipartFile avatarFile
    ) {

        return uploadService.uploadAvatar(avatarFile);
    }


    /**
     * http://198.18.0.21/upload/avatar/5f818854-1b39-4255-b632-4cdab6ca6d5a.png
     * 删除头像功能,根据现有的头像地址信息，
     *    信息是个人中心修改时获得的数据表中头像
     * @param avatarFileUrl 头像文件地址
     * @return 响应结果对象，包含上传结果信息
     */
    @PostMapping("/delAvatar")
    @ApiOperation(value = "修改图片")
    public RespMessUtil<JSONObject> delAvatar(
            @ApiParam("avatarFileUrl") @RequestParam("avatarFileUrl") String avatarFileUrl
    ) {
        return uploadService.delAvatar(avatarFileUrl);
    }


}